home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SRCBDTO.PAK / DATASET.CPP < prev    next >
Text File  |  1997-05-06  |  28KB  |  1,018 lines

  1. //-----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // dataset.cpp
  6. // TDataSet and TDBDataSet wrapper classes
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <vdbt\bdto.h>
  10.  
  11. #pragma hdrstop
  12.  
  13. #include "wrapit.h"
  14. #include "misc.h"
  15.  
  16. //-----------------------------------------------------------------------------
  17.  
  18. static void _export STDAPICALLTYPE DataSetNotifyEventCallback( int32 data, PITDataSet dataset )
  19. {
  20.     if (data)
  21.     {
  22.         PTDataSet ezDataSet = WrapPITDataSet( dataset );
  23.  
  24.         TDataSetNotifySource* source = (TDataSetNotifySource*) data;
  25.         (*source)( *ezDataSet );
  26.  
  27.         if (ezDataSet)
  28.             delete ezDataSet;
  29.     }
  30. }
  31.  
  32. void TDataSet::AttachBeforeOpen( const TBdtEventSourceBase&, bool attach )
  33. {
  34.     if (dataset)
  35.     {
  36.         AttachedBeforeOpen = attach;
  37.         if (attach)
  38.             dataset->AttachBeforeOpen( DataSetNotifyEventCallback, (int32) &BeforeOpenSource );
  39.         else
  40.             dataset->DetachBeforeOpen( DataSetNotifyEventCallback, (int32) &BeforeOpenSource );
  41.     }
  42. }
  43.  
  44. void TDataSet::AttachAfterOpen( const TBdtEventSourceBase&, bool attach )
  45. {
  46.     if (dataset)
  47.     {
  48.         AttachedAfterOpen = attach;
  49.         if (attach)
  50.             dataset->AttachAfterOpen( DataSetNotifyEventCallback, (int32) &AfterOpenSource );
  51.         else
  52.             dataset->DetachAfterOpen( DataSetNotifyEventCallback, (int32) &AfterOpenSource );
  53.     }
  54. }
  55.  
  56. void TDataSet::AttachBeforeClose( const TBdtEventSourceBase&, bool attach )
  57. {
  58.     if (dataset)
  59.     {
  60.         AttachedBeforeClose = attach;
  61.         if (attach)
  62.             dataset->AttachBeforeClose( DataSetNotifyEventCallback, (int32) &BeforeCloseSource );
  63.         else
  64.             dataset->DetachBeforeClose( DataSetNotifyEventCallback, (int32) &BeforeCloseSource );
  65.     }
  66. }
  67.  
  68. void TDataSet::AttachAfterClose( const TBdtEventSourceBase&, bool attach )
  69. {
  70.     if (dataset)
  71.     {
  72.         AttachedAfterClose = attach;
  73.         if (attach)
  74.             dataset->AttachAfterClose( DataSetNotifyEventCallback, (int32) &AfterCloseSource );
  75.         else
  76.             dataset->DetachAfterClose( DataSetNotifyEventCallback, (int32) &AfterCloseSource );
  77.     }
  78. }
  79.  
  80. void TDataSet::AttachBeforeInsert( const TBdtEventSourceBase&, bool attach )
  81. {
  82.     if (dataset)
  83.     {
  84.         AttachedBeforeInsert = attach;
  85.         if (attach)
  86.             dataset->AttachBeforeInsert( DataSetNotifyEventCallback, (int32) &BeforeInsertSource );
  87.         else
  88.             dataset->DetachBeforeInsert( DataSetNotifyEventCallback, (int32) &BeforeInsertSource );
  89.     }
  90. }
  91.  
  92. void TDataSet::AttachAfterInsert( const TBdtEventSourceBase&, bool attach )
  93. {
  94.     if (dataset)
  95.     {
  96.         AttachedAfterInsert = attach;
  97.         if (attach)
  98.             dataset->AttachAfterInsert( DataSetNotifyEventCallback, (int32) &AfterInsertSource );
  99.         else
  100.             dataset->DetachAfterInsert( DataSetNotifyEventCallback, (int32) &AfterInsertSource );
  101.     }
  102. }
  103.  
  104. void TDataSet::AttachBeforeEdit( const TBdtEventSourceBase&, bool attach )
  105. {
  106.     if (dataset)
  107.     {
  108.         AttachedBeforeEdit = attach;
  109.         if (attach)
  110.             dataset->AttachBeforeEdit( DataSetNotifyEventCallback, (int32) &BeforeEditSource );
  111.         else
  112.             dataset->DetachBeforeEdit( DataSetNotifyEventCallback, (int32) &BeforeEditSource );
  113.     }
  114. }
  115.  
  116. void TDataSet::AttachAfterEdit( const TBdtEventSourceBase&, bool attach )
  117. {
  118.     if (dataset)
  119.     {
  120.         AttachedAfterEdit = attach;
  121.         if (attach)
  122.             dataset->AttachAfterEdit( DataSetNotifyEventCallback, (int32) &AfterEditSource );
  123.         else
  124.             dataset->DetachAfterEdit( DataSetNotifyEventCallback, (int32) &AfterEditSource );
  125.     }
  126. }
  127.  
  128. void TDataSet::AttachBeforePost( const TBdtEventSourceBase&, bool attach )
  129. {
  130.     if (dataset)
  131.     {
  132.         AttachedBeforePost = attach;
  133.         if (attach)
  134.             dataset->AttachBeforePost( DataSetNotifyEventCallback, (int32) &BeforePostSource );
  135.         else
  136.             dataset->DetachBeforePost( DataSetNotifyEventCallback, (int32) &BeforePostSource );
  137.     }
  138. }
  139.  
  140. void TDataSet::AttachAfterPost( const TBdtEventSourceBase&, bool attach )
  141. {
  142.     if (dataset)
  143.     {
  144.         AttachedAfterPost = attach;
  145.         if (attach)
  146.             dataset->AttachAfterPost( DataSetNotifyEventCallback, (int32) &AfterPostSource );
  147.         else
  148.             dataset->DetachAfterPost( DataSetNotifyEventCallback, (int32) &AfterPostSource );
  149.     }
  150. }
  151.  
  152. void TDataSet::AttachBeforeCancel( const TBdtEventSourceBase&, bool attach )
  153. {
  154.     if (dataset)
  155.     {
  156.         AttachedBeforeCancel = attach;
  157.         if (attach)
  158.             dataset->AttachBeforeCancel( DataSetNotifyEventCallback, (int32) &BeforeCancelSource );
  159.         else
  160.             dataset->DetachBeforeCancel( DataSetNotifyEventCallback, (int32) &BeforeCancelSource );
  161.     }
  162. }
  163.  
  164. void TDataSet::AttachAfterCancel( const TBdtEventSourceBase&, bool attach )
  165. {
  166.     if (dataset)
  167.     {
  168.         AttachedAfterCancel = attach;
  169.         if (attach)
  170.             dataset->AttachAfterCancel( DataSetNotifyEventCallback, (int32) &AfterCancelSource );
  171.         else
  172.             dataset->DetachAfterCancel( DataSetNotifyEventCallback, (int32) &AfterCancelSource );
  173.     }
  174. }
  175.  
  176. void TDataSet::AttachBeforeDelete( const TBdtEventSourceBase&, bool attach )
  177. {
  178.     if (dataset)
  179.     {
  180.         AttachedBeforeDelete = attach;
  181.         if (attach)
  182.             dataset->AttachBeforeDelete( DataSetNotifyEventCallback, (int32) &BeforeDeleteSource );
  183.         else
  184.             dataset->DetachBeforeDelete( DataSetNotifyEventCallback, (int32) &BeforeDeleteSource );
  185.     }
  186. }
  187.  
  188. void TDataSet::AttachAfterDelete( const TBdtEventSourceBase&, bool attach )
  189. {
  190.     if (dataset)
  191.     {
  192.         AttachedAfterDelete = attach;
  193.         if (attach)
  194.             dataset->AttachAfterDelete( DataSetNotifyEventCallback, (int32) &AfterDeleteSource );
  195.         else
  196.             dataset->DetachAfterDelete( DataSetNotifyEventCallback, (int32) &AfterDeleteSource );
  197.     }
  198. }
  199.  
  200. void TDataSet::AttachOnNewRecord( const TBdtEventSourceBase&, bool attach )
  201. {
  202.     if (dataset)
  203.     {
  204.         AttachedOnNewRecord = attach;
  205.         if (attach)
  206.             dataset->AttachOnNewRecord( DataSetNotifyEventCallback, (int32) &OnNewRecordSource );
  207.         else
  208.             dataset->DetachOnNewRecord( DataSetNotifyEventCallback, (int32) &OnNewRecordSource );
  209.     }
  210. }
  211.  
  212. void TDataSet::AttachOnCalcFields( const TBdtEventSourceBase&, bool attach )
  213. {
  214.     if (dataset)
  215.     {
  216.         AttachedOnCalcFields = attach;
  217.         if (attach)
  218.             dataset->AttachOnCalcFields( DataSetNotifyEventCallback, (int32) &OnCalcFieldsSource );
  219.         else
  220.             dataset->DetachOnCalcFields( DataSetNotifyEventCallback, (int32) &OnCalcFieldsSource );
  221.     }
  222. }
  223.  
  224. void TDataSet::DetachEvents( void )
  225. {
  226.     if (dataset)
  227.     {
  228.         if (AttachedBeforeOpen)
  229.             dataset->DetachBeforeOpen( DataSetNotifyEventCallback, (int32) &BeforeOpenSource );
  230.         if (AttachedAfterOpen)
  231.             dataset->DetachAfterOpen( DataSetNotifyEventCallback, (int32) &AfterOpenSource );
  232.         if (AttachedBeforeClose)
  233.             dataset->DetachBeforeClose( DataSetNotifyEventCallback, (int32) &BeforeCloseSource );
  234.         if (AttachedAfterClose)
  235.             dataset->DetachAfterClose( DataSetNotifyEventCallback, (int32) &AfterCloseSource );
  236.         if (AttachedBeforeInsert)
  237.             dataset->DetachBeforeInsert( DataSetNotifyEventCallback, (int32) &BeforeInsertSource );
  238.         if (AttachedAfterInsert)
  239.             dataset->DetachAfterInsert( DataSetNotifyEventCallback, (int32) &AfterInsertSource );
  240.         if (AttachedBeforeEdit)
  241.             dataset->DetachBeforeEdit( DataSetNotifyEventCallback, (int32) &BeforeEditSource );
  242.         if (AttachedAfterEdit)
  243.             dataset->DetachAfterEdit( DataSetNotifyEventCallback, (int32) &AfterEditSource );
  244.         if (AttachedBeforePost)
  245.             dataset->DetachBeforePost( DataSetNotifyEventCallback, (int32) &BeforePostSource );
  246.         if (AttachedAfterPost)
  247.             dataset->DetachAfterPost( DataSetNotifyEventCallback, (int32) &AfterPostSource );
  248.         if (AttachedBeforeCancel)
  249.             dataset->DetachBeforeCancel( DataSetNotifyEventCallback, (int32) &BeforeCancelSource );
  250.         if (AttachedAfterCancel)
  251.             dataset->DetachAfterCancel( DataSetNotifyEventCallback, (int32) &AfterCancelSource );
  252.         if (AttachedBeforeDelete)
  253.             dataset->DetachBeforeDelete( DataSetNotifyEventCallback, (int32) &BeforeDeleteSource );
  254.         if (AttachedAfterDelete)
  255.             dataset->DetachAfterDelete( DataSetNotifyEventCallback, (int32) &AfterDeleteSource );
  256.         if (AttachedOnNewRecord)
  257.             dataset->DetachOnNewRecord( DataSetNotifyEventCallback, (int32) &OnNewRecordSource );
  258.         if (AttachedOnCalcFields)
  259.             dataset->DetachOnCalcFields( DataSetNotifyEventCallback, (int32) &OnCalcFieldsSource );
  260.     }
  261. }
  262.  
  263. void TDataSet::ReattachEvents( void )
  264. {
  265.     if (dataset)
  266.     {
  267.         if (AttachedBeforeOpen)
  268.             dataset->AttachBeforeOpen( DataSetNotifyEventCallback, (int32) &BeforeOpenSource );
  269.         if (AttachedAfterOpen)
  270.             dataset->AttachAfterOpen( DataSetNotifyEventCallback, (int32) &AfterOpenSource );
  271.         if (AttachedBeforeClose)
  272.             dataset->AttachBeforeClose( DataSetNotifyEventCallback, (int32) &BeforeCloseSource );
  273.         if (AttachedAfterClose)
  274.             dataset->AttachAfterClose( DataSetNotifyEventCallback, (int32) &AfterCloseSource );
  275.         if (AttachedBeforeInsert)
  276.             dataset->AttachBeforeInsert( DataSetNotifyEventCallback, (int32) &BeforeInsertSource );
  277.         if (AttachedAfterInsert)
  278.             dataset->AttachAfterInsert( DataSetNotifyEventCallback, (int32) &AfterInsertSource );
  279.         if (AttachedBeforeEdit)
  280.             dataset->AttachBeforeEdit( DataSetNotifyEventCallback, (int32) &BeforeEditSource );
  281.         if (AttachedAfterEdit)
  282.             dataset->AttachAfterEdit( DataSetNotifyEventCallback, (int32) &AfterEditSource );
  283.         if (AttachedBeforePost)
  284.             dataset->AttachBeforePost( DataSetNotifyEventCallback, (int32) &BeforePostSource );
  285.         if (AttachedAfterPost)
  286.             dataset->AttachAfterPost( DataSetNotifyEventCallback, (int32) &AfterPostSource );
  287.         if (AttachedBeforeCancel)
  288.             dataset->AttachBeforeCancel( DataSetNotifyEventCallback, (int32) &BeforeCancelSource );
  289.         if (AttachedAfterCancel)
  290.             dataset->AttachAfterCancel( DataSetNotifyEventCallback, (int32) &AfterCancelSource );
  291.         if (AttachedBeforeDelete)
  292.             dataset->AttachBeforeDelete( DataSetNotifyEventCallback, (int32) &BeforeDeleteSource );
  293.         if (AttachedAfterDelete)
  294.             dataset->AttachAfterDelete( DataSetNotifyEventCallback, (int32) &AfterDeleteSource );
  295.         if (AttachedOnNewRecord)
  296.             dataset->AttachOnNewRecord( DataSetNotifyEventCallback, (int32) &OnNewRecordSource );
  297.         if (AttachedOnCalcFields)
  298.             dataset->AttachOnCalcFields( DataSetNotifyEventCallback, (int32) &OnCalcFieldsSource );
  299.     }
  300. }
  301.  
  302. //-----------------------------------------------------------------------------
  303.  
  304. void TDataSet::SetTDataSet( PIUnknown p )
  305. {
  306.     dataset = 0;
  307.     if (p)
  308.         p->QueryInterface( IID_ITDataSet, (void**) &dataset );
  309.     ReattachEvents();
  310. }
  311.  
  312. void TDataSet::ClearTDataSet( void )
  313. {
  314.     DetachEvents();
  315.     if (dataset)
  316.     {
  317.         dataset->Release();
  318.         dataset = 0;
  319.     }
  320. }
  321.  
  322. TDataSet::TDataSet( void ) :
  323.     TBDTComponent(),
  324.     BeforeOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeOpen ) ),
  325.     AttachedBeforeOpen( false ),
  326.     AfterOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterOpen ) ),
  327.     AttachedAfterOpen( false ),
  328.     BeforeCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeClose ) ),
  329.     AttachedBeforeClose( false ),
  330.     AfterCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterClose ) ),
  331.     AttachedAfterClose( false ),
  332.     BeforeInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeInsert ) ),
  333.     AttachedBeforeInsert( false ),
  334.     AfterInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterInsert ) ),
  335.     AttachedAfterInsert( false ),
  336.     BeforeEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeEdit ) ),
  337.     AttachedBeforeEdit( false ),
  338.     AfterEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterEdit ) ),
  339.     AttachedAfterEdit( false ),
  340.     BeforePostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforePost ) ),
  341.     AttachedBeforePost( false ),
  342.     AfterPostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterPost ) ),
  343.     AttachedAfterPost( false ),
  344.     BeforeCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeCancel ) ),
  345.     AttachedBeforeCancel( false ),
  346.     AfterCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterCancel ) ),
  347.     AttachedAfterCancel( false ),
  348.     BeforeDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeDelete ) ),
  349.     AttachedBeforeDelete( false ),
  350.     AfterDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterDelete ) ),
  351.     AttachedAfterDelete( false ),
  352.     OnNewRecordSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnNewRecord ) ),
  353.     AttachedOnNewRecord( false ),
  354.     OnCalcFieldsSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnCalcFields ) ),
  355.     AttachedOnCalcFields( false )
  356. {
  357.     SetTDataSet( 0 );
  358. }
  359.  
  360. TDataSet::TDataSet( PITDataSet p ) :
  361.     TBDTComponent( p ),
  362.     BeforeOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeOpen ) ),
  363.     AttachedBeforeOpen( false ),
  364.     AfterOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterOpen ) ),
  365.     AttachedAfterOpen( false ),
  366.     BeforeCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeClose ) ),
  367.     AttachedBeforeClose( false ),
  368.     AfterCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterClose ) ),
  369.     AttachedAfterClose( false ),
  370.     BeforeInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeInsert ) ),
  371.     AttachedBeforeInsert( false ),
  372.     AfterInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterInsert ) ),
  373.     AttachedAfterInsert( false ),
  374.     BeforeEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeEdit ) ),
  375.     AttachedBeforeEdit( false ),
  376.     AfterEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterEdit ) ),
  377.     AttachedAfterEdit( false ),
  378.     BeforePostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforePost ) ),
  379.     AttachedBeforePost( false ),
  380.     AfterPostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterPost ) ),
  381.     AttachedAfterPost( false ),
  382.     BeforeCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeCancel ) ),
  383.     AttachedBeforeCancel( false ),
  384.     AfterCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterCancel ) ),
  385.     AttachedAfterCancel( false ),
  386.     BeforeDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeDelete ) ),
  387.     AttachedBeforeDelete( false ),
  388.     AfterDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterDelete ) ),
  389.     AttachedAfterDelete( false ),
  390.     OnNewRecordSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnNewRecord ) ),
  391.     AttachedOnNewRecord( false ),
  392.     OnCalcFieldsSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnCalcFields ) ),
  393.     AttachedOnCalcFields( false )
  394. {
  395.     SetTDataSet( p );
  396. }
  397.  
  398. TDataSet::TDataSet( const TDataSet& p ) :
  399.     TBDTComponent( p ),
  400.     BeforeOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeOpen ) ),
  401.     AttachedBeforeOpen( false ),
  402.     AfterOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterOpen ) ),
  403.     AttachedAfterOpen( false ),
  404.     BeforeCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeClose ) ),
  405.     AttachedBeforeClose( false ),
  406.     AfterCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterClose ) ),
  407.     AttachedAfterClose( false ),
  408.     BeforeInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeInsert ) ),
  409.     AttachedBeforeInsert( false ),
  410.     AfterInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterInsert ) ),
  411.     AttachedAfterInsert( false ),
  412.     BeforeEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeEdit ) ),
  413.     AttachedBeforeEdit( false ),
  414.     AfterEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterEdit ) ),
  415.     AttachedAfterEdit( false ),
  416.     BeforePostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforePost ) ),
  417.     AttachedBeforePost( false ),
  418.     AfterPostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterPost ) ),
  419.     AttachedAfterPost( false ),
  420.     BeforeCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeCancel ) ),
  421.     AttachedBeforeCancel( false ),
  422.     AfterCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterCancel ) ),
  423.     AttachedAfterCancel( false ),
  424.     BeforeDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeDelete ) ),
  425.     AttachedBeforeDelete( false ),
  426.     AfterDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterDelete ) ),
  427.     AttachedAfterDelete( false ),
  428.     OnNewRecordSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnNewRecord ) ),
  429.     AttachedOnNewRecord( false ),
  430.     OnCalcFieldsSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnCalcFields ) ),
  431.     AttachedOnCalcFields( false )
  432. {
  433.     SetTDataSet( p.dataset );
  434. }
  435.  
  436. TDataSet::TDataSet( PTDataSet p ) :
  437.     TBDTComponent( p ),
  438.     BeforeOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeOpen ) ),
  439.     AttachedBeforeOpen( false ),
  440.     AfterOpenSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterOpen ) ),
  441.     AttachedAfterOpen( false ),
  442.     BeforeCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeClose ) ),
  443.     AttachedBeforeClose( false ),
  444.     AfterCloseSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterClose ) ),
  445.     AttachedAfterClose( false ),
  446.     BeforeInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeInsert ) ),
  447.     AttachedBeforeInsert( false ),
  448.     AfterInsertSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterInsert ) ),
  449.     AttachedAfterInsert( false ),
  450.     BeforeEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeEdit ) ),
  451.     AttachedBeforeEdit( false ),
  452.     AfterEditSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterEdit ) ),
  453.     AttachedAfterEdit( false ),
  454.     BeforePostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforePost ) ),
  455.     AttachedBeforePost( false ),
  456.     AfterPostSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterPost ) ),
  457.     AttachedAfterPost( false ),
  458.     BeforeCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeCancel ) ),
  459.     AttachedBeforeCancel( false ),
  460.     AfterCancelSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterCancel ) ),
  461.     AttachedAfterCancel( false ),
  462.     BeforeDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachBeforeDelete ) ),
  463.     AttachedBeforeDelete( false ),
  464.     AfterDeleteSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachAfterDelete ) ),
  465.     AttachedAfterDelete( false ),
  466.     OnNewRecordSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnNewRecord ) ),
  467.     AttachedOnNewRecord( false ),
  468.     OnCalcFieldsSource( SrcAttach_MFUNCTOR( *this, &TDataSet::AttachOnCalcFields ) ),
  469.     AttachedOnCalcFields( false )
  470. {
  471.     SetTDataSet( p ? p->dataset : 0 );
  472. }
  473.  
  474. TDataSet& TDataSet::operator=( PITDataSet p )
  475. {
  476.     TBDTComponent::operator=(p);
  477.     ClearTDataSet();
  478.     SetTDataSet( p );
  479.     return *this;
  480. }
  481.  
  482. TDataSet& TDataSet::operator=( const TDataSet& p )
  483. {
  484.     if (this != &p)
  485.     {
  486.         TBDTComponent::operator=(p);
  487.         ClearTDataSet();
  488.         SetTDataSet( p.dataset );
  489.     }
  490.     return *this;
  491. }
  492.  
  493. int TDataSet::operator==( const TDataSet& p ) const
  494. {
  495.     if (this == &p)
  496.         return true;
  497.     if (dataset == p.dataset)
  498.         return true;
  499.     return false;
  500. }
  501.  
  502. int TDataSet::operator!=( const TDataSet& p ) const
  503. {
  504.     return ! operator==(p);
  505. }
  506.  
  507. TDataSet::~TDataSet()
  508. {
  509.     ClearTDataSet();
  510. }
  511.  
  512. void TDataSet::SetPIT( PIUnknown p )
  513. {
  514.     ClearTDataSet();
  515.     SetTDataSet( p );
  516.     TBDTComponent::SetPIT( dataset );
  517. }
  518.  
  519. LPSTR TDataSet::ActiveBuffer( void )
  520. {
  521.     if (dataset)
  522.         return dataset->ActiveBuffer();
  523.     return 0;
  524. }
  525.  
  526. void TDataSet::Append( void )
  527. {
  528.     if (dataset)
  529.         dataset->Append();
  530. }
  531.  
  532. void TDataSet::AppendRecord( TVarRecs& values )
  533. {
  534.     if (dataset)
  535.         dataset->AppendRecord( values.Count, values.Variants );
  536. }
  537.  
  538. void TDataSet::Cancel( void )
  539. {
  540.     if (dataset)
  541.         dataset->Cancel();
  542. }
  543.  
  544. void TDataSet::CheckBrowseMode( void )
  545. {
  546.     if (dataset)
  547.         dataset->CheckBrowseMode();
  548. }
  549.  
  550. void TDataSet::ClearFields( void )
  551. {
  552.     if (dataset)
  553.         dataset->ClearFields();
  554. }
  555.  
  556. void TDataSet::Close( void )
  557. {
  558.     if (dataset)
  559.         dataset->Close();
  560. }
  561.  
  562. void TDataSet::CursorPosChanged( void )
  563. {
  564.     if (dataset)
  565.         dataset->CursorPosChanged();
  566. }
  567.  
  568. void TDataSet::Delete( void )
  569. {
  570.     if (dataset)
  571.         dataset->Delete();
  572. }
  573.  
  574. void TDataSet::DisableControls( void )
  575. {
  576.     if (dataset)
  577.         dataset->DisableControls();
  578. }
  579.  
  580. void TDataSet::Edit( void )
  581. {
  582.     if (dataset)
  583.         dataset->Edit();
  584. }
  585.  
  586. void TDataSet::EnableControls( void )
  587. {
  588.     if (dataset)
  589.         dataset->EnableControls();
  590. }
  591.  
  592. DEFINE_BDTO_OBJECTMETHOD1( TDataSet, TField, PITField, FieldByName, string& );
  593.  
  594. void TDataSet::CallFieldByName( string& n, TField& f )
  595. {
  596.     if (dataset)
  597.     {
  598.         PITField pit = dataset->FieldByName( AnyString(n).GetPITAnyString() );
  599.         if (pit)
  600.         {
  601.             f.SetPIT( pit );
  602.             pit->Release();
  603.         }
  604.     }
  605. }
  606.  
  607. DEFINE_BDTO_OBJECTMETHOD1( TDataSet, TField, PITField, FindField, string& );
  608.  
  609. void TDataSet::CallFindField( string& n, TField& f )
  610. {
  611.     if (dataset)
  612.     {
  613.         PITField pit = dataset->FindField( AnyString(n).GetPITAnyString() );
  614.         if (pit)
  615.         {
  616.             f.SetPIT( pit );
  617.             pit->Release();
  618.         }
  619.     }
  620. }
  621.  
  622. void TDataSet::First( void )
  623. {
  624.     if (dataset)
  625.         dataset->First();
  626. }
  627.  
  628. void TDataSet::FreeBookmark( TBookmark bm )
  629. {
  630.     if (dataset)
  631.         dataset->FreeBookmark( bm );
  632. }
  633.  
  634. TBookmark TDataSet::GetBookmark( void )
  635. {
  636.     if (dataset)
  637.         return dataset->GetBookmark();
  638.     return 0;
  639. }
  640.  
  641. bool TDataSet::GetCurrentRecord( LPSTR buffer )
  642. {
  643.     if (dataset)
  644.         return MakeBool( dataset->GetCurrentRecord( buffer ) );
  645.     return false;
  646. }
  647.  
  648. void TDataSet::GetFieldNames( TStrings& list )
  649. {
  650.     if (dataset)
  651.         dataset->GetFieldNames( list.GetPITStrings() );
  652. }
  653.  
  654. void TDataSet::GotoBookmark( TBookmark bm )
  655. {
  656.     if (dataset)
  657.         dataset->GotoBookmark( bm );
  658. }
  659.  
  660. void TDataSet::Insert( void )
  661. {
  662.     if (dataset)
  663.         dataset->Insert();
  664. }
  665.  
  666. void TDataSet::InsertRecord( TVarRecs& values )
  667. {
  668.     if (dataset)
  669.         dataset->InsertRecord( values.Count, values.Variants );
  670. }
  671.  
  672. bool TDataSet::IsLinkedTo( TDataSource& source )
  673. {
  674.     if (dataset)
  675.         return MakeBool( dataset->IsLinkedTo( source.GetPITDataSource() ) );
  676.     return false;
  677. }
  678.  
  679. void TDataSet::Last( void )
  680. {
  681.     if (dataset)
  682.         dataset->Last();
  683. }
  684.  
  685. void TDataSet::MoveBy( int distance )
  686. {
  687.     if (dataset)
  688.         dataset->MoveBy( distance );
  689. }
  690.  
  691. void TDataSet::Next( void )
  692. {
  693.     if (dataset)
  694.         dataset->Next();
  695. }
  696.  
  697. void TDataSet::Open( void )
  698. {
  699.     if (dataset)
  700.         dataset->Open();
  701. }
  702.  
  703. void TDataSet::Post( void )
  704. {
  705.     if (dataset)
  706.         dataset->Post();
  707. }
  708.  
  709. void TDataSet::Prior( void )
  710. {
  711.     if (dataset)
  712.         dataset->Prior();
  713. }
  714.  
  715. void TDataSet::Refresh( void )
  716. {
  717.     if (dataset)
  718.         dataset->Refresh();
  719. }
  720.  
  721. void TDataSet::Resync( TResyncMode mode )
  722. {
  723.     if (dataset)
  724.         dataset->Resync( mode );
  725. }
  726.  
  727. void TDataSet::SetFields( TVarRecs& values )
  728. {
  729.     if (dataset)
  730.         dataset->SetFields( values.Count, values.Variants );
  731. }
  732.  
  733. void TDataSet::UpdateCursorPos( void )
  734. {
  735.     if (dataset)
  736.         dataset->UpdateCursorPos();
  737. }
  738.  
  739. void TDataSet::UpdateRecord( void )
  740. {
  741.     if (dataset)
  742.         dataset->UpdateRecord();
  743. }
  744.  
  745. DEFINE_BDTO_PROP_RO( TDataSet, bool, AtBOF );
  746. DEFINE_BDTO_PROP_RO( TDataSet, bool, CanModify );
  747. DEFINE_BDTO_OBJECTPROP_RO_FAST( TDataSet, TDataSource, PITDataSource, DataSource );
  748. DEFINE_BDTO_PROP_RO( TDataSet, bool, DefaultFields );
  749. DEFINE_BDTO_PROP_RO( TDataSet, bool, AtEOF );
  750. DEFINE_BDTO_PROP_RO( TDataSet, int, FieldCount );
  751. DEFINE_BDTO_OBJECTPROP_RO_FAST( TDataSet, TFieldDefs, PITFieldDefs, FieldDefs );
  752. DEFINE_BDTO_ARRAYOBJECTPROP_RO_FAST( TDataSet, TField, PITField, Fields, int );
  753. DEFINE_BDTO_PROP_RO( TDataSet, hDBICur, Handle );
  754. DEFINE_BDTO_PROP_RO( TDataSet, bool, Modified );
  755. DEFINE_BDTO_PROP_RO( TDataSet, int32, RecordCount );
  756. DEFINE_BDTO_PROP_RO( TDataSet, uint16, RecordSize );
  757. DEFINE_BDTO_PROP_RO( TDataSet, TDataSetState, State );
  758. DEFINE_BDTO_PROP_RO( TDataSet, TLocale, Locale );
  759.  
  760. void TDataSet::GetAtBOF( bool& b )
  761. {
  762.     if (dataset)
  763.         b = MakeBool( dataset->get_AtBOF() );
  764. }
  765.  
  766. void TDataSet::GetCanModify( bool& c )
  767. {
  768.     if (dataset)
  769.         c = MakeBool( dataset->get_CanModify() );
  770. }
  771.  
  772. void TDataSet::GetDataSource( TDataSource& d )
  773. {
  774.     if (dataset)
  775.     {
  776.         PITDataSource pit = dataset->get_DataSource();
  777.         if (pit)
  778.         {
  779.             d.SetPIT( pit );
  780.             pit->Release();
  781.         }
  782.     }
  783. }
  784.  
  785. void TDataSet::GetDefaultFields( bool& d )
  786. {
  787.     if (dataset)
  788.         d = MakeBool( dataset->get_DefaultFields() );
  789. }
  790.  
  791. void TDataSet::GetAtEOF( bool& e )
  792. {
  793.     if (dataset)
  794.         e = MakeBool( dataset->get_AtEOF() );
  795. }
  796.  
  797. void TDataSet::GetFieldCount( int& c )
  798. {
  799.     if (dataset)
  800.         c = dataset->get_FieldCount();
  801. }
  802.  
  803. void TDataSet::GetFieldDefs( TFieldDefs& f )
  804. {
  805.     if (dataset)
  806.     {
  807.         PITFieldDefs pit = dataset->get_FieldDefs();
  808.         if (pit)
  809.         {
  810.             f.SetPIT( pit );
  811.             pit->Release();
  812.         }
  813.     }
  814. }
  815.  
  816. void TDataSet::GetFields( int i, TField& f )
  817. {
  818.     if (dataset)
  819.     {
  820.         PITField pit = dataset->get_Fields( i );
  821.         if (pit)
  822.         {
  823.             f.SetPIT( pit );
  824.             pit->Release();
  825.         }
  826.     }
  827. }
  828.  
  829. void TDataSet::GetHandle( hDBICur& h )
  830. {
  831.     if (dataset)
  832.         h = dataset->get_Handle();
  833. }
  834.  
  835. void TDataSet::GetModified( bool& m )
  836. {
  837.     if (dataset)
  838.         m = MakeBool( dataset->get_Modified() );
  839. }
  840.  
  841. void TDataSet::GetRecordCount( int32& c )
  842. {
  843.     if (dataset)
  844.         c = dataset->get_RecordCount();
  845. }
  846.  
  847. void TDataSet::GetRecordSize( uint16& s )
  848. {
  849.     if (dataset)
  850.         s = dataset->get_RecordSize();
  851. }
  852.  
  853. void TDataSet::GetState( TDataSetState& s )
  854. {
  855.     if (dataset)
  856.         s = dataset->get_State();
  857. }
  858.  
  859. void TDataSet::GetLocale( TLocale& l )
  860. {
  861.     if (dataset)
  862.         l = dataset->get_Locale();
  863. }
  864.  
  865. DEFINE_BDTO_PROP_RW( TDataSet, bool, Active );
  866. DEFINE_BDTO_PROP_RW( TDataSet, bool, AutoCalcFields );
  867.  
  868. void TDataSet::GetActive( bool& a )
  869. {
  870.     if (dataset)
  871.         a = MakeBool( dataset->get_Active() );
  872. }
  873.  
  874. void TDataSet::SetActive( bool a )
  875. {
  876.     if (dataset)
  877.         dataset->put_Active( MakeVariantBool( a ) );
  878. }
  879.  
  880. void TDataSet::GetAutoCalcFields( bool& a )
  881. {
  882.     if (dataset)
  883.         a = MakeBool( dataset->get_AutoCalcFields() );
  884. }
  885.  
  886. void TDataSet::SetAutoCalcFields( bool a )
  887. {
  888.     if (dataset)
  889.         dataset->put_AutoCalcFields( MakeVariantBool( a ) );
  890. }
  891.  
  892. //-----------------------------------------------------------------------------
  893.  
  894. void TDBDataSet::SetTDBDataSet( PIUnknown p )
  895. {
  896.     dbdataset = 0;
  897.     if (p)
  898.         p->QueryInterface( IID_ITDBDataSet, (void**) &dbdataset );
  899. }
  900.  
  901. void TDBDataSet::ClearTDBDataSet( void )
  902. {
  903.     if (dbdataset)
  904.     {
  905.         dbdataset->Release();
  906.         dbdataset = 0;
  907.     }
  908. }
  909.  
  910. TDBDataSet::TDBDataSet( void ) : TDataSet()
  911. {
  912.     SetTDBDataSet( 0 );
  913. }
  914.  
  915. TDBDataSet::TDBDataSet( PITDBDataSet p) : TDataSet( p )
  916. {
  917.     SetTDBDataSet( p );
  918. }
  919.  
  920. TDBDataSet::TDBDataSet( const TDBDataSet& p ) : TDataSet( p )
  921. {
  922.     SetTDBDataSet( p.dbdataset );
  923. }
  924.  
  925. TDBDataSet::TDBDataSet( PTDBDataSet p ) : TDataSet( p )
  926. {
  927.     SetTDBDataSet( p ? p->dbdataset : 0 );
  928. }
  929.  
  930. TDBDataSet& TDBDataSet::operator=( PITDBDataSet p )
  931. {
  932.     TDataSet::operator=(p);
  933.     ClearTDBDataSet();
  934.     SetTDBDataSet( p );
  935.     return *this;
  936. }
  937.  
  938. TDBDataSet& TDBDataSet::operator=( const TDBDataSet& p )
  939. {
  940.     if (this != &p)
  941.     {
  942.         TDataSet::operator=(p);
  943.         ClearTDBDataSet();
  944.         SetTDBDataSet( p.dbdataset );
  945.     }
  946.     return *this;
  947. }
  948.  
  949. int TDBDataSet::operator==( const TDBDataSet& p ) const
  950. {
  951.     if (this == &p)
  952.         return true;
  953.     if (dbdataset == p.dbdataset)
  954.         return true;
  955.     return false;
  956. }
  957.  
  958. int TDBDataSet::operator!=( const TDBDataSet& p ) const
  959. {
  960.     return ! operator==(p);
  961. }
  962.  
  963. TDBDataSet::~TDBDataSet()
  964. {
  965.     ClearTDBDataSet();
  966. }
  967.  
  968. void TDBDataSet::SetPIT( PIUnknown p )
  969. {
  970.     ClearTDBDataSet();
  971.     SetTDBDataSet( p );
  972.     TDataSet::SetPIT( p );
  973. }
  974.  
  975. DEFINE_BDTO_OBJECTPROP_RO_FAST( TDBDataSet, TDatabase, PITDatabase, Database );
  976. DEFINE_BDTO_PROP_RO( TDBDataSet, hDBIDb, DBHandle );
  977. DEFINE_BDTO_PROP_RO( TDBDataSet, TLocale, DBLocale );
  978.  
  979. void TDBDataSet::GetDatabase( TDatabase& d )
  980. {
  981.     if (dbdataset)
  982.     {
  983.         PITDatabase pit = dbdataset->get_Database();
  984.         if (pit)
  985.         {
  986.             d.SetPIT( pit );
  987.             pit->Release();
  988.         }
  989.     }
  990. }
  991.  
  992. void TDBDataSet::GetDBHandle( hDBIDb& h )
  993. {
  994.     if (dbdataset)
  995.         h = dbdataset->get_DBHandle();
  996. }
  997.  
  998. void TDBDataSet::GetDBLocale( TLocale& l )
  999. {
  1000.     if (dbdataset)
  1001.         l = dbdataset->get_DBLocale();
  1002. }
  1003.  
  1004. DEFINE_BDTO_OBJECTPROP_RW( TDBDataSet, string, DatabaseName );
  1005.  
  1006. void TDBDataSet::GetDatabaseName( string& s )
  1007. {
  1008.     if (dbdataset)
  1009.         AnyString( dbdataset->get_DatabaseName() ).GetString( s );
  1010. }
  1011.  
  1012. void TDBDataSet::SetDatabaseName( const string& n )
  1013. {
  1014.     if (dbdataset)
  1015.         dbdataset->put_DatabaseName( AnyString(n).GetPITAnyString() );
  1016. }
  1017.  
  1018.